package com.wywah.common.exception;

import com.wywah.common.http.HttpStatus;
import com.wywah.common.utils.StringUtils;

/**
 * 基础异常
 */
public class BaseException extends RuntimeException {
    private final int code;
    private final String msg;


    public BaseException(int code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public BaseException(Throwable cause, int code, String msg) {
        super(msg, cause);
        this.code = code;
        this.msg = msg;
    }

    public BaseException(String msg) {
        super(msg);
        this.code = HttpStatus.FAIL.code;
        this.msg = msg;
    }

    public BaseException(Throwable cause) {
        super(cause);
        this.code = HttpStatus.FAIL.code;
        this.msg = cause.getMessage();
    }

    public BaseException(Throwable cause, String msg) {
        super(msg,cause);
        this.code = HttpStatus.FAIL.code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return StringUtils.isBlank(msg) ? super.getMessage() : msg;
    }
}
